<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<div class="tip-container aui-gutter-column-sm">
    <span>{{'protection_disk_level_restore_tip_label' | i18n}}</span>
</div>
<div class="restore-tree">
    <lv-form class="aui-gutter-column-md formGroup target-btn">
        <lv-form-item>
            <lv-form-label>{{'protection_selected_copy_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <span>{{rowCopy.display_timestamp | date: 'yyyy-MM-dd HH:mm:ss'}}</span>
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label lvRequired>
                {{'protection_restore_target_label' | i18n}}
                <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_fc_disk_restore_tip_label' | i18n}}"
                    lvTooltipTheme="light" class="configform-constraint" lvColorState='true'></i>
            </lv-form-label>
            <lv-form-control>
                <lv-group lvRowGutter="8px" [lvColumns]='["auto", "100px"]'>
                    <input [ngModel]="inputTarget" lv-input readOnly
                        placeholder="{{'protection_select_fc_vm_target_label' | i18n}}" />
                    <button (click)="selectRecoveryTarget()" lv-button>
                        {{'common_restore_select_label' | i18n}}
                    </button>
                </lv-group>
            </lv-form-control>
        </lv-form-item>
    </lv-form>
    <lv-group class="grid-position">
        <div class="file-level-restore-tree hcs-restore-list-tree margin-space restore-lv-paginator-simple">
            <ng-container *ngTemplateOutlet="allFileData">
            </ng-container>
        </div>
        <div class="file-level-restore-tree hcs-restore-list-tree restore-lv-paginator-simple">
            <ng-container *ngTemplateOutlet="selectedFileData">
            </ng-container>
        </div>
    </lv-group>
</div>

<ng-template #allFileData>
    <lv-pro-table #dataTable [config]="datasTableConfig" [data]="tableData"></lv-pro-table>
</ng-template>

<ng-template #selectedFileData>
    <lv-pro-table #selectTable [config]="tableConfig" [data]="selectData"></lv-pro-table>
</ng-template>

<ng-template #deskDeviceTpl let-item>
    <span *ngIf="_isEmpty(inputTarget)"> -- </span>
    <span *ngIf="!_isEmpty(inputTarget) && isOriginPosition" class="origin-position">{{item.datastore}}</span>
    <span *ngIf="!_isEmpty(inputTarget) && !isOriginPosition && isSame">{{sameDataStore.name}}</span>

    <lv-select *ngIf="!_isEmpty(inputTarget) && !isOriginPosition && !isSame" class="disk-select"
        [lvOptions]="targetDiskOptions" [(ngModel)]="item.targetDisk" (ngModelChange)='diskChange($event, item)'
        [lvContentTemplate]='contentTpl' lvValueKey='id'>
        <lv-select-trigger>
            <span>
                <i [lv-tooltip]="item?.errorTip" *ngIf="item?.errorTip" lv-icon='lv-icon-status-warning-info'
                    class="icon-warning"></i>
                <span class="dataStore-label" lv-overflow
                    [ngClass]="{'dataStore-label-waring' : item?.errorTip}">{{item?.targetDiskName}}</span>
            </span>
        </lv-select-trigger>
        <ng-template #contentTpl let-item>
            <div class="select-disk-label">
                <i *ngIf="item.errorTip" [lv-tooltip]="item?.errorTip" lv-icon='lv-icon-status-warning-info'
                    class="icon-warning"></i>
                <span lv-overflow>{{item?.name}}</span>
            </div>
        </ng-template>
    </lv-select>
</ng-template>

<ng-template #sizeTpl let-item>
    {{_isUndefined(item.size) ? '--' : item.size +'GB'}}
</ng-template>

<ng-template #dataStoreSizeTpl let-item>
    <div class="origin-position">
        <span *ngIf="_isEmpty(inputTarget)"> -- </span>
        <span *ngIf=" !_isEmpty(inputTarget) && isOriginPosition">{{_isUndefined(item.size) ? '--' : item.size
            +'GB'}}</span>
        <span *ngIf=" !_isEmpty(inputTarget) && !isOriginPosition && isSame">{{calcSize + 'GB'}}</span>
        <span *ngIf=" !_isEmpty(inputTarget) && !isOriginPosition && !isSame">{{_isUndefined(item.size) ? '--' :
            item.size + 'GB'}}</span>
    </div>

</ng-template>

<ng-template #helpExtraTpl>
    <div class="custom-icon">
        <i lv-icon="aui-icon-help" lv-tooltip="{{'common_target_disk_remain_help_label' | i18n}}"
            lvTooltipPosition="rightTop" lvTooltipTheme="light" lvColorState='true'></i>
    </div>
</ng-template>